<extend name="Base:main" />
<block name="content">
<style>
	.style1{
		width: 100%;
		margin: 0px auto;
		margin-bottom:20px;
		border:1px solid #96C2F1;
		background-color: #EFF7FF;
		padding:1%;
		font-size:14px;
	}
</style>
<div class="tpl-content-wrapper">
            <div class="tpl-content-page-title">
               第三方平台绑定
            </div>
            <ol class="am-breadcrumb">
                <li><a href="#" class="am-icon-home">首页</a></li>
                <li><a href="#">账户管理</a></li>
                <li class="am-active">平台列表</li>
            </ol>
            <div class="tpl-portlet-components">
               
                <div class="tpl-block">
                    <div class="am-g">
						<div class="style1">
							注意事项：<br>
							1、可填域名（例：http://www.shenghuigo.com），需使用字母、数字及“-”的组合，不支持IP地址、端口号及短链域名。<br>
							2、填写的域名须通过ICP备案的验证。<br>
							3、将文件{:get_platform_check_data($login_info.id)}.txt（<a href="{:U('Accunt/platformCheckKey')}" target="blank">点击下载</a>）上传至填写域名的web服务器（或虚拟主机）根目录下，并确保可以访问。
						</div>
						<form class="am-form" action="{:U('Accunt/platformBind')}" method="get">
							<div class="am-u-sm-12 am-u-md-5">
								<label class=" am-form-label">平台名称</label> <span style="display: inline-block;"><input type="text"  name="name" value="{$Think.get.name}"  class=" am-form-field"></span>
								<button type="submit" class="am-btn am-btn-secondary am-radius"><i class="am-icon-hand-pointer-o"></i> 搜索</button>
								<a href="{:U('Accunt/platformBindAdd')}" title="第三方平台绑定添加" width="650" height="480" menu="load_iframe_url" class="am-btn am-btn-secondary am-radius"><i class="am-icon-plus-square"></i> 增加数据</a>
							</div>
						</form>
                    </div>
                    <div class="am-g">
                        <div class="am-u-sm-12">
                          
                                <table class="am-table am-table-striped am-table-hover table-main">
                                    <thead>
                                        <tr>
                                            <th class="table-check"> <input class="check-all" type="checkbox" value=""></th>
                                            <th>平台名称</th>
                                            <th>平台URL</th>
                                            <th width="130">状态</th>
                                            <th width="130">通信检测</th>
                                            <th width="200">创建时间</th>
                                            <th class="table-set" width="250">操作</th>
                                        </tr>
                                    </thead>
                                    <tbody>
									<empty name="lists">
										<tr>
                                            <td colspan="10" style=" height:60px;line-height:60px; text-align:center">暂无信息</td>
                                        </tr>
									<else />
										<volist name="lists" id="val">
                                        <tr data-id="{$val.id}">
                                            <td><input class="ids" type="checkbox" value="{$val['id']}"></td>
                                            <td>{$val.name}</td>
                                            <td>{$val.url}</td>
                                            <td>
												<div class="tpl-switch" data-value="{$val.status}" data-id="{$val.id}">
													<input type="checkbox" class="ios-switch bigswitch tpl-switch-btn" <eq name="val.status" value="1">checked</eq>>
													<div class="tpl-switch-btn-view"><div></div></div>
												</div>
											</td>
                                            <td>未检测</td>
                                            <td>{$val['create_time']}</td>
                                            <td>
                                                <div class="am-btn-toolbar">
                                                    <div class="am-btn-group am-btn-group-xs">
                                                        <button href="{:U('Accunt/apiBand' , array('id'=> $val['id']))}" title="平台【{$val.name}】接口绑定" width="650" height="480" menu="load_iframe_url" class="am-btn am-btn-default am-btn-xs am-text-secondary"><span class="am-icon-pencil-square-o"></span> 接口绑定</button>
                                                        <button href="{:U('Accunt/platformBindSave' , array('id'=> $val['id']))}" title="平台【{$val.name}】信息修改" width="650" height="480" menu="load_iframe_url" class="am-btn am-btn-default am-btn-xs am-text-secondary"><span class="am-icon-pencil-square-o"></span> 编辑</button>
                                                        <button href="{:U('Accunt/platformBindDel' , array('id' => $val['id']))}" request_type="ajax" menu="tip_menu" title="要删除这个【{$val.name}】平台？" class="am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only"><span class="am-icon-trash-o"></span> 删除</button>
                                                    </div>
                                                </div>
                                            </td>
                                        </tr>
										</volist>
									</empty>
                                    </tbody>
                                </table>
                                <div class="am-cf">

                                    <div class="am-fr">
                                        <ul class="am-pagination tpl-pagination">
                                            {$page}
                                        </ul>
                                    </div>
                                </div>
                                <hr>
								<div class="am-u-sm-12 am-u-md-6">
									<div class="am-btn-toolbar">
										<div class="am-btn-group am-btn-group-xs">
											<button type="button" class="am-btn am-btn-default am-btn-success" id="txjc_but"><span class="am-icon-plus"></span> 通信检测 </button>
										</div>
									</div>
								</div>
                        </div>
                    </div>
                </div>
                <div class="tpl-alert"></div>
            </div>

        </div>
    <script>
		$(".check-all").click(function () {
			$(".ids").prop("checked", this.checked);
		});
		$('div.tpl-switch').click(function(){
			var data = $(this).attr('data-value') == 1 ? 0 : 1;
			$.get('{:U('Accunt/platformBindStatusSave')}' , { status: data, id : $(this).attr('data-id') });
		});
		$('#txjc_but').click(function(){
			var _self = $('input.ids:checked');
			if( _self.length <= 0 ) {
				error( '请勾选检测平台！' );
				return false;
			}
			_self.each(function(){
				sendCheckData( $(this) );
			});
		});
		function sendCheckData( obj ) {
			var obj_self = obj.closest('tr');
			var data_id = obj_self.attr('data-id');
			obj_self.find('td').eq(4).html('<span style="color:red">正在检测...</span>');
			$.get('{:U('Accunt/platformTesting')}',{ id:data_id },function(data){
				if( data.status == 1 ) {
					obj_self.find('td').eq(4).html('<span style="color:green">通信正常</span>');
				} else {
					obj_self.find('td').eq(4).html('<span style="color:red">无法通信</span>');
				}
			},'json');
		}
    </script>
    
</block>